<template>
	<view>
		<!-- 搜索框 -->
		<uni-list>
			<uni-search-bar  @blur="getSchool" class="uni-mt-10" radius="5" placeholder="输入学校名称" clearButton="auto" cancelButton="none"  />
		</uni-list>
		<!-- 当前地址 -->
		<uni-section title="湖北民族大学" titleFontSize="18px">
			<template v-slot:decoration>
				<view>
					<uni-icons type="paperplane-filled"  size="20"></uni-icons>
				</view>
			</template>
			<template v-slot:right>
				<view style="font-size: small;">
					当前位置
				</view>
			</template>
		</uni-section>
		<!-- 附近地址 -->
		<uni-section title="附近地址" type="line" class="addressList">
			<template v-slot:decoration>
				<view>
					<uni-icons type="map-pin-ellipse" color="#0278FF" size="20"></uni-icons>
				</view>
			</template>
			<uni-list>
				<uni-list-item v-for="item,index in deptList" :title="item.name" clickable	 @click="chooseAddress(item)" /> 
			</uni-list>
		</uni-section>
	</view>
</template>

<script>
	import { getAddress } from "@/api/print/address.js";
	export default {
		data() {
			return {
				longitude: null,
				latitude: null,
				DeptName: null,
				deptList: [{name:"湖北民族大学"},{name:"湖北民族学院"}]
			}
		},
		onReady(){
			console.log("@@@@");
			// #ifdef MP-WEIXIN
			wx.getLocation({
			 type: 'wgs84',
			 success (res) {
				console.log(res);
			  this.latitude = res.latitude
			  this.longitude = res.longitude 
				console.log('当前位置的经度：' + res.longitude);
				console.log('当前位置的纬度：' + res.latitude);
				 
			 }
			}) 
			// #endif
			// #ifndef MP-WEIXIN
				uni.getLocation({
					type: 'wgs84',
					success: function (res) {
					this.latitude = res.latitude
					this.longitude = res.longitude 
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
					}
				});
			// #endif

		},
		methods: {
			// 获取学校
			async getSchool(){ 
				console.log("afd")
				wx.getLocation({
				 type: 'wgs84',
				 success (res) {
				console.log(res);
				  this.latitude = res.latitude
				  this.longitude = res.longitude 
					console.log('当前位置的经度：' + res.longitude);
					console.log('当前位置的纬度：' + res.latitude);
					 
				 },
					fail(res) {
						console.log(res);
					}
				}) 
				const res = await getAddress(this.longitude,this.latitude,this.DeptName);
				console.log(res);
			},
			//选择学校
			chooseAddress(){
				console.log("选择学校地址");
			}
		}
	}
</script>

<style>
  .decoration{
    width: 6px;
    height: 6px;
		margin-right: 4px;
    border-radius: 50%;
		background-color: $uni-success;
  }
	/* 附近地址 */
	.addressList{
		margin-top: 20rpx;
	}
</style>
